//
// Created by hjie on 23-12-9.
//
#pragma once

#include "base_util.h"
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <libavutil/frame.h>
#include <string>
#include <iostream>
#include "input_output_context.h"
#include "message_queue.h"
extern "C"
{
	#include <libavcodec/avcodec.h>
	#include <libavfilter/avfilter.h>
	#include <libavfilter/buffersrc.h>
	#include <libavfilter/version.h>
	#include <libavformat/avformat.h>
	#include <libavcodec/avcodec.h>
	#include <libavfilter/avfilter.h>
	#include <libavfilter/buffersink.h>
	#include <libavutil/pixdesc.h>
	#include <libavutil/pixfmt.h>
}

struct NullSrcAndOverlay
{
	InputFormatContext m_input_ctx;
    InputFormatContext m_input_ctx_1;
	OutputFormatContext m_output_ctx;
	AVFilterGraph * m_graph{nullptr};
	AVFilterContext * m_nullsrc_ctx;
	AVFilterContext * m_overlay_ctx;
	AVFilterContext * m_buffer_ctx;
	AVFilterContext * m_buffer_ctx_1;
	AVFilterContext * m_buffer_sink_ctx;

	int64_t m_packet_index{0};
};
struct MessageQueueData
{
	PacketMessageQueue m_read_packet_queue;
    PacketMessageQueue m_read_packet_queue_1;
	FrameMessageQueue  m_decoder_frame_queue;
    FrameMessageQueue  m_decoder_frame_queue_1;
	FrameMessageQueue  m_filter_frame_queue;
	PacketMessageQueue m_encoder_packet_queue;
};

int NullSrcAndOverlayInit(NullSrcAndOverlay & data);
int InitInputStream(NullSrcAndOverlay & data);
int FilterProcessFrameInput0(NullSrcAndOverlay & data, AVFrame * frame, FrameMessageQueue & message_queue);
int FilterProcessFrameInput1(NullSrcAndOverlay & data, AVFrame * frame, FrameMessageQueue & message_queue);
int FilterProcessFrame(NullSrcAndOverlay & data, AVFilterContext * buffer, AVFrame * frame, FrameMessageQueue & message_queue);

int InitOutputData(NullSrcAndOverlay & data, AVFrame * frame);